<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>会议详情</title>
    <link rel="stylesheet" type="text/css" href="../../css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <script src="../../js/mui.min.js"></script>
    <script src="../../js/jquery.min.js"></script>
    <script src="../../js/vue.js"></script>
    <script src="../../js/main.js"></script>
    <script src="../../js/autosize.min.js"></script>
</head>
<body>
<div id="app">
    <header class="mui-bar mui-bar-nav">
        <span class="back" @click="back"></span>
        <span class="cross" @click="close"></span>
        <h1 class="mui-title" style="left: 80px;right: 80px">会议详情</h1>
        <span class="edit-name fr" v-if="createUser ==loginUser"
              onclick="deleteMeeting()">删除</span>
    </header>
    <div class="mui-content" style="padding-bottom: 70px">
        <ul class="summary-list">
            <li>
                <div class="summary-l">会议主题：</div>
                <div class="summary-r">{{title}}</div>
            </li>
            <li>
                <div class="summary-l">会议内容：</div>
                <div class="summary-r">{{content}}</div>
            </li>
            <li>
                <div class="summary-l">会议地点：</div>
                <div class="summary-r">{{place}}</div>
            </li>
            <li>
                <div class="summary-l">会议时间：</div>
                <div class="summary-r" style="text-align: right;color: #2c9ae8;">{{startTime}}</div>
            </li>
            <li class="state" :class="stateValue | getClass">{{stateValue}}</li>
        </ul>
        <div class="add-sender add-me">
            <p>参会人</p>
            <!--<div class="report-headimg more-person">华</div>-->
            <!--<p class="sender">添加</p>-->
            <div class="report-headimg fl" v-for="(item,index) in participants"
                 style="margin-top: 5px; margin-right: 5px;">{{item.name}}
            </div>
            <div class="sender" style="height: 60px"></div>
            <div class="clearFix"></div>
        </div>

        <div class="add-sender add-me">
            <p>会议记录员<span>（唯一）</span></p>
            <div class="report-headimg more-person">{{recordUserName}}</div>
            <!--<p class="sender">添加</p>-->
        </div>
        <div class="discuss-area" v-if="comments.length>0">
            <p class="discuss-title">评论</p>
            <ul class="discuss-list">
                <li class="report-top" v-for="(item,index) in comments">
                    <div class="report-headimg fl">{{item.userName}}</div>
                    <div class="report-info discuss-text">
                        <p>{{item.userName}}<span class="fr">{{item.createTime}}</span></p>
                        <div class="discuss-info">
                            {{item.content}}
                        </div>
                    </div>
                </li>
            </ul>
        </div>
        <ul class="report-footer me-footer" v-if="createUser ==loginUser">
            <li>
                <div class="footer-btn footer-btn-fir" @click="checkPoint(0,'watch')">查看会议纪要</div>
            </li>
            <li>
                <div class="footer-btn footer-btn-sec" v-if="start && state==1" @click="endMeeting">结束会议</div>
                <div class="footer-btn footer-btn-sec" v-else="!start || state==3" style="background-color: grey ">
                    结束会议
                </div>
            </li>
            <li>
                <div class="footer-btn footer-btn-sec" v-if="state!=2" @click="cancelMeeting">取消会议</div>
                <div class="footer-btn footer-btn-sec" v-else="state==2" style="background-color: grey ">取消会议</div>
            </li>
            <li>
                <div class="footer-btn footer-btn-sec"  @click="comment" id="promptBtn">评论</div>
            </li>

            <div class="clear"></div>
        </ul>
        <ul class="report-footer me-footer" v-if="recorder == loginUser">
            <li>
                <div class="footer-btn footer-btn-fir" @click="checkPoint(1,'add')">添加会议纪要</div>
            </li>
            <!--<li>-->
            <!--<div class="footer-btn footer-btn-sec" v-if="start" @click="endMeeting">结束会议</div>-->
            <!--<div class="footer-btn footer-btn-sec" v-else="!start" style="background-color: grey ">结束会议</div>-->
            <!--</li>-->
            <li>
                <div class="footer-btn footer-btn-sec"  @click="comment" id="promptBtn">评论</div>
            </li>
            <li>
                <div class="footer-btn footer-btn-fir" @click="checkPoint(1,'watch')">查看会议纪要</div>
            </li>

            <div class="clear"></div>
        </ul>
        <ul class="report-footer" v-if="createUser !=loginUser && recorder != loginUser">
            <li>
                <div class="footer-btn footer-btn-fir" @click="checkPoint(0,'watch')">查看会议纪要</div>
            </li>
            <li>
                <div class="footer-btn footer-btn-sec"  @click="comment" id="promptBtn">评论</div>
            </li>
            <div class="clear"></div>
        </ul>
        <div class="report-footer" v-if="state == 2">
            <div class="submit-btn" @click="comment" id="promptBtn">评论</div>
        </div>
    </div>
</div>
</body>

<script>

    function sendInfoToJava(name) {
        //调用android程序中的方法，并传递参数
        javascript:WebView.showInfoFromJs(name);
    }

    var id = GetQueryString("id");
    var app = new Vue({
        el: "#app",
        data: function () {
            return {
                id: 2,
                title: "",          //会议主题
                content: "",        //会议内容
                place: "",          //会议地点
                startTime: "",      //会议开始时间
                recordUserName: "", //记录员名字
                participants: [],    //todo 参会人员列表
                comments: [] ,        //评价列表
                createUser : "", // 创建人
                loginUser: localStorage.userName,
                companyId:localStorage.companyId,
                start: false,
                state: 1,//状态值
                stateValue:"",//状态名
                recorder:""//记录员登录名
            }
        },
        filters:{
           getClass: function(input){
               if(input == '未开始'){
                   return "notStart";
               }else if(input == '已结束'){
                   return 'finished';
               }else if(input == '已取消'){
                   return 'withdraw';
               }
           }
        },
        methods: {
            back: function () {
                var name = "back";
                sendInfoToJava(name);
            },
            close: function () {
                var name = "close";
                sendInfoToJava(name);
            },
            init: function () {
                var this_obj = this;
                id = 1;
                console.log(id);
                var url = "/meeting/zgMeeting/" + id;
                getAjax(url, function (res) {
                    if (null != res && res.code == 0) {
                        var data = res.obj;

                        for (var i in data.zgMeetingCommentReturnList) {
                            var hName = data.zgMeetingCommentReturnList[i]['userName'].slice(-2);
                            data.zgMeetingCommentReturnList[i]['userName'] = hName;
                        }
                        console.log(data.participantList);
                        for (var i in data.participantList) {
                            var hName = data.participantList[i]['name'].slice(-2);
                            data.participantList[i]['name'] = hName;
                        }

                        this_obj.id = data.zgMeetingId;
                        this_obj.title = data.zgMeetingTextReturnList[0].content;
                        this_obj.content = data.zgMeetingTextReturnList[1].content;
                        this_obj.place = data.zgMeetingTextReturnList[2].content;
                        this_obj.startTime = data.startTime;
                        this_obj.recordUserName =  data.recordUserName.slice(-2);
                        this_obj.participants = data.participantList;
                        this_obj.comments = data.zgMeetingCommentReturnList;

                        this_obj.recorder = JSON.parse(data.recordListJson).loginName;
                        console.log(data);
                        console.log(data.start);
                        this_obj.stateValue = data.stateValue;
                        this_obj.state = data.state;
                        this_obj.start = data.start;
                        this_obj.createUser = data.createUser;
                    }
                }, function (res) {
                    alert("请求失败");
                });
            },
            checkPoint: function (type,msg) {
                window.location.href = "meeting_summary.html?id=" + id +"&type=" + type +"&msg=" +msg;
            },
            cancelMeeting: function () {
                var url = "/meeting/zgMeeting/" + id + "/cancel";
                var btnArray = ['取消', '确定'];
                mui.confirm('确定要取消本次会议吗？', '', btnArray, function (e) {
                    if (e.index == 1) {
                        common_ajax(url, null, function (res) {
                            if (null != res && res.code == 0) {
                                mui.toast("取消成功");
                                setTimeout(function () {
                                    location.href = "meeting_arrange.html";
                                }, 1500);
                            }
                        }, function (res) {
                            mui.toast("取消失败");
                        })
                    } else {
                    }
                })
            },
            endMeeting: function () {
                var url = "/meeting/zgMeeting/" + id + "/end";

                var btnArray = ['取消', '确定'];
                mui.confirm('确定要结束本次会议吗？', '', btnArray, function (e) {
                    if (e.index == 1) {
                        common_ajax(url, null, function (res) {
                            if (null != res && res.code == 0) {
                                mui.toast("结束成功");
                                setTimeout(function () {
                                    location.href = "meeting_arrange.html";
                                }, 1500);
                            }
                        }, function (res) {
                            mui.toast("结束失败");
                        })
                    } else {
                    }
                })
            },
            comment: function() {
                var this_obj =this;
                document.getElementById("promptBtn").addEventListener('tap', function(e) {
                    e.detail.gesture.preventDefault(); //修复iOS 8.x平台存在的bug，使用plus.nativeUI.prompt会造成输入法闪一下又没了
                    var btnArray = ['取消', '确定'];
                    mui.prompt('请输入你对本次会议的评语：', '评论', this_obj.title, btnArray, function(e) {
                        if (e.index == 1) {
                            var data ={
                                        "content": e.value,
                                        "loginName": localStorage.userName,
                                        "meetingId": this_obj.id
                                      }
                             var url = '/meeting/zgMeetingComment';
                            common_ajax(url,data,function(res) {
                                mui.toast('评论成功');
                                this_obj.init();
                            },function(res) {
                                mui.toast(res,errorMsg)
                            })
                        } else {
                            mui.toast('你点了取消按钮');
                        }
                    })
                });
            }
        }
    });
    app.init();


    function deleteMeeting() {
        var url = "/meeting/zgMeeting/" + id + "/delete";
        var btnArray = ['取消', '确定'];
        mui.confirm('确定要删除本次会议吗？', '', btnArray, function (e) {
            if (e.index == 1) {
                common_ajax(url, null, function (res) {
                    if (null != res && res.code == 0) {
                        mui.toast("删除成功");
                        setTimeout(function () {
                            location.href = "meeting_arrange.html";
                        }, 1500);
                    }
                }, function (res) {
                    mui.toast("删除失败");
                })
            } else {
            }
        })
    }

    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null)return unescape(r[2]);
        return null;
    }

    $(function () {
        $(".add-btn").click(function () {
            $(".pop-up-bg").show();
        });
        $(".close").click(function () {
            $(".pop-up-bg").hide();
        });
    })

</script>


</html>